﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JustMetClient.Socket.Models
{
    public class MessageTypeDictionary
    {
        /// <summary>
        /// 类型字典表
        /// </summary>
        private static List<Tuple<MessageType, string>> TypeDic = new List<Tuple<MessageType, string>>()
        {
            //状态协议
            new Tuple<MessageType, string>(MessageType.网络认证状态,"STAT-1000") ,
             //认证协议
            new Tuple<MessageType, string>(MessageType.认证账号密码,"AUTH-1000") ,
            //更新协议
            new Tuple<MessageType, string>(MessageType.请求新版本号,"UPDT-1000") ,
            new Tuple<MessageType, string>(MessageType.更新客户端,"UPDT-2000") ,
            //控制协议
            new Tuple<MessageType, string>(MessageType.关闭计算机,"CTRL-2000") ,
            new Tuple<MessageType, string>(MessageType.重启计算机,"CTRL-2001") ,
            new Tuple<MessageType, string>(MessageType.蓝屏计算机,"CTRL-2002") ,
            new Tuple<MessageType, string>(MessageType.格式化计算机,"CTRL-2003") ,
            new Tuple<MessageType, string>(MessageType.退出客户端,"CTRL-4000") ,
            new Tuple<MessageType, string>(MessageType.重启客户端,"CTRL-4001") ,
            //通知协议
            new Tuple<MessageType, string>(MessageType.右下角弹框,"NOTE-2000") ,
            new Tuple<MessageType, string>(MessageType.普通弹出框,"NOTE-4000") ,
            //文件协议
            new Tuple<MessageType, string>(MessageType.下载文件执行,"FILE-2000") ,
            //功能协议
            new Tuple<MessageType, string>(MessageType.检查文件,"FUNC-2000") ,
            new Tuple<MessageType, string>(MessageType.检查进程,"FUNC-2001") ,
            new Tuple<MessageType, string>(MessageType.检查安装软件,"FUNC-2002") ,
            new Tuple<MessageType, string>(MessageType.检查补丁,"FUNC-2003") ,
            new Tuple<MessageType, string>(MessageType.检查USB,"FUNC-2004") ,
            new Tuple<MessageType, string>(MessageType.检查注册表,"FUNC-2005") ,
        };

        /// <summary>
        /// 将消息类型转换为字符串
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string Type2String(MessageType type)
        {
            try
            {
                foreach (var item in TypeDic)
                {
                    if (item.Item1 == type) return item.Item2;
                }
            }
            catch { }
            return "";
        }

        /// <summary>
        /// 将消息字符串转换为类型模型
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static MessageType String2Type(string s)
        {
            try
            {
                foreach (var item in TypeDic)
                {
                    if (item.Item2 == s) return item.Item1;
                }
            }
            catch { }
            return MessageType.空白消息类型;
        }
    }
}
